<?php 
    include 'top.php'; 
    include '../util.php';
?>
<script src="uploadify/swfobject.js"  language="javascript" ></script>
<script src="uploadify/jquery.uploadify.v2.1.4.min.js"  language="javascript" ></script>
<link href="uploadify/uploadify.css" rel="stylesheet" type="text/css" />

<?php
    $bannerId = make_safe($_REQUEST['banner']);

    if ($_REQUEST['action'] == 'edit') {
     $oldimages=make_safe($_POST["oldimages"]);
  $path =  "upfiles/tmp/".$_POST['images'];
   $type=strstr($path,'.');
   $path2 = "upfiles/".$data."1".$type;
   $type=strtolower($type); 
   if($type==".jpg"  or $type==".jpge" or $type==".jpeg" or $type==".gif" or $type==".doc" or $type==".xls" or $type==".bmp" or $type==".pdf" ){
	//move_uploaded_file("../upfiles/tmp/".$path,"../upfiles/".$path2);//上传图片
	copy("../".$path,"../".$path2);
	unlink("../".$path);
			 
	if($oldimages!=""){@unlink("../".$oldimages);@unlink("../".$oldimages.'-68x68.jpg');}//删除旧图片
}
else
{
	$path2=$oldimages;
}

        $sql = sprintf("UPDATE banner SET `title` = '%s', `images` = '%s', `sort_index` = %d WHERE `id` = %d ", make_safe($_REQUEST['title']), $path2, make_safe($_REQUEST['sort_index']), $bannerId);
        $result = mysql_query($sql);
        if ($result !== false) {
            Util::jsAlert('修改首頁圖片成功', 'banner.php');
        }
    }
?>

<script type="text/javascript">
$(function() {
    $('#uploadify').uploadify({
        'uploader': 'uploadify/uploadify.swf',
        'cancelImg': 'uploadify/cancel.png',
        'script': 'upload.php',
        'folder': 'files',
        'buttonText':'Choose',
        'multi': false,
        'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
        'fileDesc': 'Image Files',
        'auto': true,
        'queueSizeLimit': 1,
        'scriptData': {'<?php echo session_name();?>':'<?php echo session_id();?>','name': $(this).attr('name'),'responsetype':'sizeinfo'},
        'displayData': 'speed',
        'onComplete': function(event,queueID,fileObj,response,data) {
    
            var responseObj = eval("("+response+")");
            var fileName = responseObj.name;
            $('input[name="images"]').val(fileName);
            $('#bannerImg').attr('src','../upfiles/tmp/' + fileName);
        },
        'onError':function(event,queueId,fileObj,errorObj) {
            alert(errorObj);
        }
    });

    $('form[name="banner_edit"]').submit(function() {
        if ( isNaN(parseInt($(this).find('input[name="sort_index"]').val())) ){
            alert('圖片顯示順序必須為數字，請重新修改');
            $(this).find('input[name="sort_index"]').val('').focus();
            return false;
        }
        return true;
    });
})
</script>

    <div id="top-3">
        <div id="m-text-1">
            <ul>
                <li>系統管理功能</li>
                <li><a href="admin_manage.php">管理管理員</a></li>
                <li><a href="banner.php">管理首頁圖片</a></li>
            </ul>
        </div>
	 
	 
        <div id="m-text-2_banner">
          <ul>
            <li>首页图片管理 -> 修改</li>
          </ul>
        </div>
		
        <?php 
            $sql = sprintf('SELECT * FROM banner WHERE id = %d', $bannerId);
            $result = mysql_query($sql);
            $bannerInfo = mysql_fetch_assoc($result);
            if ($bannerInfo == null) {
                Util::jsAlert('指定的首页图片不存在', 'admin/banner.php');
            }
        ?>
		<div id="m-text-2">
            <form name="banner_edit" action="<?php echo $_SERVER['PHP_SELF']; ?>?banner=<?php echo $bannerId;?>&action=edit" method="post">
                <input name="oldimages" type="hidden" value="<?php echo $bannerInfo['images'];?>"/>
                <table cellpadding='0' cellspacing='0' border='0'>
                    <tr>
                        <td width="200">圖片:</td>
                        <td>
                            <input name="images" type="hidden" value=""/>
                            <img src="<?php echo '../'.$bannerInfo['images']; ?>" height="110" id="bannerImg"/><br/>
                            <input id="uploadify" name="uploadifyimgs" type="file" value="<?php echo $bannerInfo['images'];?>"/>
                        </td>
                    </tr>
                    <tr>
                        <td>圖片標題:</td>
                        <td>
                            <input type="textfield" name="title" value="<?php echo $bannerInfo['title']; ?>" />
                        </td>
                    </tr>
                    <tr>
                        <td>顯示順序:</td>
                        <td>
                            <input type="textfield" name="sort_index" value="<?php echo $bannerInfo['sort_index']; ?>" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <input type="submit" value="修改" />
                        </td>
                    </tr>
                </table>
            </form>
        </div>

    </div>
  </div>
</div>

<div id="botton"><div id="copyright"><table border="0" cellpadding="0" cellspacing="0" class="copy">
  <tr>
    <td>© COPYRIGHTS 2010 INC. APARTMENT STUDIO All rights reserved.</td>
  </tr>
</table>
</div></div>
</body>
</html>
